/*package cn.meomis.common.security;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import cn.meomis.common.Constants;
import cn.meomis.model.Role;
import cn.meomis.model.User;
import cn.meomis.service.RoleService;
import cn.meomis.service.UserService;

@Service
public class UserDetailService implements UserDetailsService {
	*//**
	 * Logger for this class
	 *//*
	private static final Logger logger = Logger
			.getLogger(UserDetailService.class);

	@Resource
	private UserService userInfoServiceImpl;
	@Resource
	private RoleService roleService;

	public UserDetailService() {

	}


	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {

		if (logger.isDebugEnabled()) {
			logger.debug("loadUserByUsername(String) - start");  
		}
		Collection<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
		// 取得用户的密码
		User userinfo = userInfoServiceImpl.findUserByEmailAndState(username, Constants.USER_NORMAL_STATE);
		if (userinfo == null) {
			String message = "用户" + username + "不存在,或者该用户被禁用！";
			logger.error(message);
			throw new UsernameNotFoundException(message);
		}

		// 获得用户的角色
		Role role = new Role();
		role.setId(userinfo.getRoleId());
		role = roleService.get(role);
		logger.info("收到页面提交登陆用户:" + username + "__" + role.getRoleName());
		GrantedAuthorityImpl grantedAuthorityImpl = new GrantedAuthorityImpl(
				role.getRoleName());
		auths.add(grantedAuthorityImpl);

		NewUserInfo newInfo = null;
		newInfo = new NewUserInfo(username, userinfo.getPasswd(), true, true, true, true,
				auths, userinfo.getUserrealname());

		if ( userinfo.getUserrealname()!=null ) {
			newInfo.setUserName(userinfo.getEmail());
		} else {
			newInfo.setUserName("");
		}
		logger.info("当前的auths :" + auths);


		if (logger.isDebugEnabled()) {
			logger.debug("loadUserByUsername(String) - end"); //$NON-NLS-1$  
		}
		return newInfo;
	}

}*/